package com.example.user.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.example.common.api.user.service.LoginService;
import com.example.user.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Auther: wyj
 * @Description:登录功能的service接口实现类
 */
@Service(version = "1.0.0")
@org.springframework.stereotype.Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private UserDao userDao;

    @Override
    public String login(String username){
        //利用正则表达式判断user是否符合格式
        Pattern pattern=null;
        Matcher matcher=null;
        boolean flag1=false;
        boolean flag2=false;
        pattern=Pattern.compile("^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\\\d{8}$");
        matcher=pattern.matcher(username);
        flag1=matcher.matches();
        pattern=Pattern.compile("^([a-z0-9A-Z]+[-|\\\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\\\.)+[a-zA-Z]{2,}$");
        matcher=pattern.matcher(username);
        flag2=matcher.matches();
        System.out.println("flag1:"+flag1+",flag2:"+flag2);

        //输入的user格式正确
//        if(!(flag1||flag2)){
//            //TODO 日志记录
//            return null;
//        }

        //调用持久层方法查询user
        String password = userDao.login(username);

        //对返回值就行逻辑判断
        if(password == null){
            //TODO 日志记录
        }

        System.out.println("password:"+password);
        return password;
    }
}
